Digital Output with LEDs

The digital output pins on the Pico can be used to turn a device (e.g. an LED) on or off.

LEDs are small lights that come in a variety of sizes and colours. LED stands for Light Emitting Diode.

Diodes can only allow electricity to flow one way through them, so we need to make sure we connect them the right way around otherwise they won’t light up. The short leg should go to ground and the long leg to the digital signal>


Wire up

Wire up the LED using a 220ohm resistor like this. The resistor limits the current so the LED does not burn out.

Wire up
Circuit Pico
Black GND
Blue GP13 or another GP pin

Code

Write this code and download to the Pico. The LED should flash.

See code on github
# Test blinking of an LED

import time
import board
import digitalio

# Set up the LED on pin 13 as a digital output pin
led = digitalio.DigitalInOut(board.GP13)
led.direction = digitalio.Direction.OUTPUT

# Loop forever, blinking the LED
while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)